home *** CD-ROM | disk | FTP | other *** search
- From: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
- Date: Wed, 15 Dec 93 11:08:59 +0100
- Message-Id: <9312151008.AA18526@issan.informatik.uni-dortmund.de>
- To: mint@atari.archive.umich.edu
- Subject: MiNT 1.09/MinixFS 0.6pl9: FIONREAD broken
-
- FIONREAD always returns 1 on tosfs and minixfs. On the pipefs,
- FIONREAD returns -1 if there are no writers, and FIONWRITE returns -1
- if there are no readers. This breaks cat from textutils 1.9.
- FIONREAD should always return 0 on eof. The patch fixes this.
-
- ************************* MiNT 1.09 *************************
- --- orig/pipefs.c Fri Jun 25 22:20:54 1993
- +++ pipefs.c Tue Dec 14 22:50:10 1993
- @@ -747,12 +747,13 @@
-
- this = (struct fifo *)f->fc.index;
-
- - if (mode == FIONREAD) {
- + switch (mode) {
- + case FIONREAD:
- p = (f->flags & O_HEAD) ? this->outp : this->inp;
- assert(p != 0);
- if (p->writers <= 0 || p->writers == VIRGIN_PIPE) {
- DEBUG(("pipe FIONREAD: no writers"));
- - r = -1;
- + r = 0;
- } else {
- r = p->tail - p->head;
- if (r < 0) r += PIPESIZ;
- @@ -760,12 +761,12 @@
- r = r >> 2; /* r /= 4 */
- }
- *((long *) buf) = r;
- - }
- - else if (mode == FIONWRITE) {
- + break;
- + case FIONWRITE:
- p = (f->flags & O_HEAD) ? this->inp : this->outp;
- assert(p != 0);
- if (p->readers <= 0) {
- - r = -1;
- + r = 0;
- } else {
- r = p->tail - p->head;
- if (r < 0) r += PIPESIZ;
- @@ -774,8 +775,9 @@
- r = r >> 2; /* r /= 4 */
- }
- *((long *) buf) = r;
- - }
- - else if (mode == F_SETLK || mode == F_SETLKW) {
- + break;
- + case F_SETLK:
- + case F_SETLKW:
- lck = (struct flock *)buf;
- while (this->flags & O_LOCK) {
- if (this->lockpid != curproc->pid) {
- @@ -803,8 +805,8 @@
- this->lockpid = curproc->pid;
- f->flags |= O_LOCK;
- }
- - }
- - else if (mode == F_GETLK) {
- + break;
- + case F_GETLK:
- lck = (struct flock *)buf;
- if (this->flags & O_LOCK) {
- lck->l_type = F_WRLCK;
- @@ -813,8 +815,8 @@
- }
- else
- lck->l_type = F_UNLCK;
- - }
- - else if (mode == TIOCFLUSH) {
- + break;
- + case TIOCFLUSH:
- if (this->inp) {
- this->inp->head = this->inp->tail;
- wake(IO_Q, (long)this->inp);
- @@ -823,11 +825,20 @@
- this->outp->head = this->outp->tail;
- wake(IO_Q, (long)this->outp);
- }
- - } else if (mode == TIOCIBAUD || mode == TIOCOBAUD) {
- + break;
- + case TIOCIBAUD:
- + case TIOCOBAUD:
- *(long *)buf = -1L;
- - } else if (mode == TIOCGFLAGS) {
- + break;
- + case TIOCGFLAGS:
- *((unsigned short *)buf) = 0;
- - } else if (mode >= TCURSOFF && mode <= TCURSGRATE) {
- + break;
- + case TCURSOFF:
- + case TCURSON:
- + case TCURSSRATE:
- + case TCURSBLINK:
- + case TCURSSTEADY:
- + case TCURSGRATE:
- /* kludge: this assumes TOSWIN style escape sequences */
- tty_putchar(f, (long)'\033', RAW);
- switch (mode) {
- @@ -851,7 +862,8 @@
- case TCURSGRATE:
- return this->cursrate;
- }
- - } else {
- + break;
- + default:
- /* if the file is a terminal, Fcntl will automatically
- * call tty_ioctl for us to handle 'generic' terminal
- * functions
- --- orig/tosfs.c Fri Jun 25 22:24:32 1993
- +++ ./tosfs.c Sat Nov 20 02:34:14 1993
- @@ -1147,9 +1147,17 @@
- extern int flk; /* set in main.c if _FLK already installed */
-
- - if (mode == FIONREAD || mode == FIONWRITE) {
- + switch (mode) {
- + case FIONREAD:
- + r = Fseek (0L, (int) f->devinfo, 1);
- + if (r < 0) return r;
- + *(long *) buf = Fseek (0L, (int) f->devinfo, 2) - r;
- + (void) Fseek (r, (int) f->devinfo, 0);
- + return 0;
- + case FIONWRITE:
- *((long *)buf) = 1;
- return 0;
- - }
- - else if (mode == F_SETLK || mode == F_SETLKW || mode == F_GETLK) {
- + case F_SETLK:
- + case F_SETLKW:
- + case F_GETLK:
- fl = ((struct flock *)buf);
- t.l = *fl;
- ************************* MinixFS 0.6pl9 *************************
- --- orig/minixfs/minixdev.c Sat Nov 27 19:42:24 1993
- +++ ./minixfs/minixdev.c Tue Dec 14 19:37:26 1993
- @@ -445,7 +445,18 @@
- switch (mode)
- {
- case FIONREAD:
- + {
- + d_inode rip;
- + long nread;
- + read_inode (f->fc.index, &rip, f->fc.dev);
- + nread = rip.i_size - f->pos;
- + if (nread < 0)
- + nread = 0;
- + *(long *) buf = nread;
- + return 0;
- + }
- +
- case FIONWRITE:
- {
-